package com.da.web.dorm_leave.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.da.web.dorm_leave.entity.DormLeave;
import com.da.web.dorm_leave.entity.LeaveParm;
import com.da.web.dorm_leave.mapper.DormLeaveMapper;
import com.da.web.dorm_leave.service.DormLeaveService;
import org.springframework.stereotype.Service;

/**
 * @author da
 * @time 2023/12/14 下午 3:55
 */
@Service
public class DormLeaveServiceImpl extends ServiceImpl<DormLeaveMapper, DormLeave> implements DormLeaveService {

    @Override
    public IPage<DormLeave> pageList(LeaveParm parm) {
        IPage<DormLeave> page = new Page<>(parm.getCurrentPage(), parm.getPageSize());
        //构造查询条件
        QueryWrapper<DormLeave> query = new QueryWrapper<>();
        if (StrUtil.isNotEmpty(parm.getClasses())) {
            query.lambda().like(DormLeave::getClasses, parm.getClasses());
        }
        if (StrUtil.isNotEmpty(parm.getStuName())) {
            query.lambda().like(DormLeave::getStuName, parm.getStuName());
        }
        if (StrUtil.isNotEmpty(parm.getDormName())) {
            query.lambda().like(DormLeave::getDormName, parm.getDormName());
        }
        return this.page(page, query);
    }
}
